package com.enlorenz.common.geo.map.base;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;

import com.enlorenz.common.geo.map.arcgis.ArcgisTileFilePathCreator;
import com.enlorenz.common.geo.map.google.GoogleTileFileParser;
import com.enlorenz.common.geo.map.google.GoogleTileParser;
import com.enlorenz.common.geo.map.google.GoogleTileFileParser.GoogleTileFileHook;

public class MapView extends JFrame{
	private static double lonSt=121.50;
	private static double lonEd=122.38;
	private static double latSt=29.55;
	private static double latEd=30.26;
	private static int zoom=13;
	//基础的文件路径
	private static String srcFilePath="D:\\roadmap_cn_dst";
	private static String dstFilePath="D:\\roadmap_cn_dst";

	public void run(){
		
	}
	
		public static void makebutton(JPanel frame, String name, GridBagLayout gridbag,
				GridBagConstraints c) {
			JLabel button = new JLabel();
			button.setIcon(new ImageIcon(name));
			System.out.println(name);
			button.setBounds(0, 0, 256, 256);
			gridbag.setConstraints(button, c);
			c.fill = GridBagConstraints.BOTH;
			frame.add(button);
		}

		public static void main(String[] args) {
			JFrame frame = new JFrame("Test");
			
			final JPanel jp=new JPanel();
			JScrollPane scrollPane=new JScrollPane(jp);
			frame.setContentPane(scrollPane);
			
			
			final GridBagLayout gridbag = new GridBagLayout();
			final GridBagConstraints c = new GridBagConstraints();
			final long [] ints=new long[3];
			ints[0]=0;
			ints[1]=0;
			ints[2]=0;
			frame.setSize(600, 400);
			jp.setLayout(gridbag);
			
			
			
			GoogleTileParser gtp=new GoogleTileParser();
			
			GoogleTileFileParser googleTileFileParser=new GoogleTileFileParser(gtp);
			
			googleTileFileParser.setSrcCreator(new ArcgisTileFilePathCreator());
			googleTileFileParser.setDstCreator(new ArcgisTileFilePathCreator());
			
			googleTileFileParser.setGoogleTileFileHook(new GoogleTileFileHook(){
				@Override
				public void hook(int index, long total,
						FileWrapper srcFileWp,FileWrapper dstFileWp,TileWrapper googleTileWrapper) {
				/*	System.out.println(googleTileWrapper.getX()+":"+ints[0]);
					if(googleTileWrapper.getX() != ints[0]){
						ints[0]=googleTileWrapper.getX();
						c.gridwidth = GridBagConstraints.REMAINDER; // 第一行结束
						makebutton(jp, "D:\\copote\\workspace\\ADC_BASE\\src_common\\com\\copote\\common\\map\\google\\DefaultTile.png", gridbag, c);
					}*/
					
					
					if(ints[0]!=googleTileWrapper.getX()){
						ints[0]=googleTileWrapper.getX();
						ints[1]++;
						ints[2]=0;
					}
					
					ints[2]++;
					
					c.gridx=(int)ints[1];
					c.gridy=(int)ints[2];
					System.out.println(c.gridx+":"+c.gridy);
					makebutton(jp,dstFileWp.getFullPath(), gridbag, c);
				}
			});
			
			//int totalDataNum=googleTileFileParser.initTile();
			googleTileFileParser.doParse();
			
			

			frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
			frame.setVisible(true);
		}

}
